﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class FinanceCenter_DownloadFundList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime StartTime = ShoveEL._Convert.StrToDateTime(Request["StartTime"], DateTime.Now.ToShortDateString());
        DateTime EndTime = ShoveEL._Convert.StrToDateTime(Request["EndTime"], DateTime.Now.ToShortDateString());

        int Result = 0;
        string Return = "";

        DataSet ds = DAL.Procedures.P_InComingOrOutComing.Open(StartTime, EndTime, 3, ref Result, ref Return);

        if (ds == null)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "数据库连接失败。");

            return;
        }

        DataTable dt = ds.Tables[0];
        if (dt == null)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "数据库连接失败。");

            return;
        }

        HttpResponse response;
        response = Page.Response;
        response.AppendHeader("Content-Disposition", "attachment;filename=FundList_" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
        Response.ContentType = "application/ms-excel";
        response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

        response.Write("序号\t会员ID\t会员姓名\t支出金额\t支出时间\t支出方式\t操作员\t备注\n");

        foreach (DataRow dr in dt.Rows)
        {
            response.Write(dr["sequenceNumber"].ToString() + "\t" + dr["Name"].ToString() + "\t" + dr["Realityname"].ToString() + "\t" + dr["Money"].ToString() + "\t" + dr["DateTime"].ToString() + "\t" + (ShoveEL._Convert.StrToDouble(dr["DistillFormalitiesFeesScale"].ToString(), 0) > 0 ? "支付宝支付" : "银联支付") + "\t" + dr["OperatorName"].ToString() + "\t" + dr["memo"].ToString() + "\n");
        }

        if (ds.Tables[1].Rows.Count > 0)
        {
            string strMoney = ds.Tables[1].Rows[0]["SumMoney"].ToString();
            response.Write("总计：" + ds.Tables[1].Rows[0]["SumID"].ToString() + "   总计：消费" + ((ShoveEL._Convert.StrToDouble(strMoney, 0) == 0) ? "0.00" : ShoveEL._Convert.StrToDouble(strMoney, 0).ToString()));
        }

        response.End();
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.Finance);
        RequestLoginPage = "FinanceCenter/DownloadFundList.aspx";

        base.OnInit(e);
    }

    #endregion
}
